package com.scatteredServer.controller;

import com.scatteredServer.common.Result;
import com.scatteredServer.pojo.form.add.AddIndexNotice;
import com.scatteredServer.pojo.form.update.UpdateNotice;
import com.scatteredServer.pojo.query.NoticeQuery;
import com.scatteredServer.pojo.query.PostingQuery;
import com.scatteredServer.pojo.query.ReadStatusQuery;
import com.scatteredServer.pojo.vo.*;
import com.scatteredServer.service.impl.NoticeServiceImpl;
import com.scatteredServer.service.impl.PostingServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.mail.internet.AddressException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

@RestController
@RequestMapping("s4/notice")
@Slf4j
@Tag(name = "已读未读通知管理", description = "已读未读通知管理")
public class NoticeController {

    @Autowired
    PostingServiceImpl postingService;

    @Autowired
    NoticeServiceImpl noticeService;

    @Operation(summary = "管理员获取发文已读未读情况", description = "管理员获取发文已读未读情况")
    @PostMapping("/getNoticeList")
    public Result<BaseVo<PostingReadStatusVo >> getNoticeList(@RequestBody NoticeQuery noticeQuery) {
        return postingService.getNoticeList(noticeQuery);
    }

    @Operation(summary = "通过id获取本推文最低阅读时间", description = "根据推文id，获取本推文最低阅读时间")
    @PostMapping("/getMinTimeById/{postingId}")
    public Result<String> getMinTimeById(@PathVariable String postingId) {
        return postingService.getMinTimeById(postingId);
    }

    @Operation(summary = "向教师发送首页通知 List<教师id>", description = "向教师发送首页通知")
    @PostMapping("/sendIndexNotice")
    public Result<String> sendIndexNotice(@RequestBody AddIndexNotice addIndexNotice) throws AddressException, UnsupportedEncodingException {
        return postingService.sendIndexNotice(addIndexNotice);
    }

    @Operation(summary = "教师发送已读请求（具体在阅读时候）", description = "发送已读请求")
    @PostMapping("/sendRead")
    public Result<String> sendRead(@RequestBody UpdateNotice updateNotice) {
        return postingService.sendRead(updateNotice);
    }

    @Operation(summary = "教师获取阅读状态（小红点）", description = "获取阅读状态（小红点）")
    @PostMapping("/getReadStatus")
    public Result<ReadStatusTeacher> getReadStatus(@RequestBody ReadStatusQuery readStatusQuery) {
        return postingService.getReadStatus(readStatusQuery);
    }


    @Operation(summary = "教师获取通知(首页)", description = "获取阅读状态(首页)")
    @GetMapping("/getNotice/{teacherId}")
    public Result<NoticeIndexVo> getIndexNotice(@PathVariable String teacherId) {
        return noticeService.getIndexNotice(teacherId);
    }


}
